const Router = require('koa-router');
const { pool } = require('../config/db');
const authMiddleware = require('../middleware/auth');

const router = new Router({ prefix: '/about' });

// 前台：获取关于页内容
router.get('/about', async (ctx) => {
  const [rows] = await pool.query('SELECT content FROM about WHERE id = 1');
  ctx.body = { data: rows[0]?.content || '' };
});

// 后台：更新关于页内容
router.put('/about', authMiddleware, async (ctx) => {
  const { content } = ctx.request.body;
  await pool.query('UPDATE about SET content = ? WHERE id = 1', [content]);
  ctx.body = { message: '关于页内容更新成功' };
});

module.exports = router;